package com.hyh.shiyanshiguanli.controller;


import com.hyh.shiyanshiguanli.constant.MessageConstant;
import com.hyh.shiyanshiguanli.domain.dto.*;

import com.hyh.shiyanshiguanli.domain.entity.Classify;
import com.hyh.shiyanshiguanli.domain.entity.LibManager;
import com.hyh.shiyanshiguanli.domain.result.PageResult;
import com.hyh.shiyanshiguanli.domain.result.Result;
import com.hyh.shiyanshiguanli.service.ClassifyService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/classify")
public class classifyController {

    @Autowired
    ClassifyService classifyService;

    @GetMapping("/page")
    public Result<PageResult> page(ClassifyDTO classifyDTO){
       log.info("实验室分类分页查询{}",classifyDTO);
       PageResult result = classifyService.page(classifyDTO);
       return Result.success(result);
    }

    @GetMapping("/{id}")
    public Result<Classify> selectById(@PathVariable Integer id){
        log.info("根据id查询classify{}",id);
        Classify classify = classifyService.selectById(id);
        return Result.success(classify);
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody ClassifyUpdateDTO classifyUpdateDTO){
        log.info("更新classify数据id为{}",classifyUpdateDTO.getId());
        classifyService.updateById(classifyUpdateDTO);
        return Result.success();
    }

    @PostMapping("/add")
    public Result addPublicInformation(@RequestBody ClassifyAddDTO classifyAddDTO){
        log.info("添加classify{}",classifyAddDTO);
        classifyService.add(classifyAddDTO);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(Integer id){
        log.info("删除id为{}的classify",id);
        int delete = classifyService.deleteById(id);
        if (delete == MessageConstant.SUCCESS){
            return Result.success();
        }
        else{
            return Result.error("不能删除");
        }

    }
    @GetMapping("/manager")
    public Result<List> selectManager(){
        log.info("查询所有实验室管理员");
        List<LibManager> LibManagers = classifyService.selectManager();

        return Result.success(LibManagers);
    }

}
